﻿@{
    ViewBag.Title = "分类报表";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<link href="~/Content/css/ConsignmentReport_print.css" rel="stylesheet" media="print" />
<style type="text/css">
    .print {
        display: none;
    }

    .tool_c {
        padding: 10px 0;
    }

    .btn-group {
        padding: 0 10px 0 0;
    }


    .grid_list_1_c table tr[id] td:nth-child(2) a {
        margin: 0 0.5em 0 0;
    }


    .btn-group:last-child a.btn:first-child {
        margin: 0 0.5em 0 0 !important;
    }

    .input_inline input {
        display: inline-block;
        width: 4em;
    }

    .date_area input {
        display: inline-block;
        width: 8em !important;
        margin: 0 0.2em;
    }


    .btn-group input[type=text] {
        height: 2em !important;
    }
</style>
<script>
    $(function () {
        Index.init();
    });

    var Index = {
        defaultDate:@Html.Raw(ViewData["LedgerDate"].ToString()),
        printTemplate: null,
        titlies: "{0}来料单位汇总,{0}领料单位汇总,{0}入库统计,{0}销售统计".split(","),
        curUnit: '@ViewData["curUnit"].ToString()',
        curUserName: '@ViewData["curUserName"].ToString()',
        curDate: '@ViewData["curDate"].ToString()',
        curTime: '@ViewData["curTime"].ToString()',
        dataList:{
            "0":null,
            "1":null,
            "2":null,
            "3":null
        },
        printItemTemplate: "",
        init: function () {
            with (Index) {
                printItemTemplate = $("#print1 .page").html();

                initControl();

                loadDataList();
            }
        },
        initControl: function () {
            $.renderMy97Datepicker();

            $("[date-control]").val(Index.defaultDate);

            $("[date-control]").on("click", function () {
                WdatePicker({ dateFmt: 'yyyyMM', minDate: '2000-1', maxDate: '2050-12' });
            });

            $('select').bindSelect();
            //来料单位
            $("#FHappenComNO1").bindSelect({
                url: "/WareHouse/Consignment/GetHappenComies",
                id: "UnitNO",
                text: "UnitNOName"
            });
            //批次查询 btn_search1
            $("#btn_search1").on("click", function () {
                var $gridList1 = $("#gridList1");

                var conn1 = $.buildPostParam("FAccountDate,FHappenComNO", "1");

                $gridList1.jqGrid('setGridParam', {
                    postData: conn1,
                }).trigger('reloadGrid');
            });
            //打印      
            $("#butnPrint1").on("click", function () {
                $("#print1").jqprint();
            });
            //导出
            $("#butnExport1").on("click", function () {
                var param = { id: "V_JSK_13_ML_StoLJKConAcco_Mid_DWCR", param: Index.buildExportConn("FAccountDate,FHappenComNO".split(","), "1") };
                
                Index.defaultDate != $("#FAccountDate1").val() && (param.id = "V_JSK_16_MX_StoLJKListAcco_Arc_DWCR");

                var url = "/Common/ExcelExportById?{0}".format($.param(param));

                location.href = url;
            });
            //领料单位
            $("#FHappenComNO2").bindSelect({
                url: "/WareHouse/Consignment/GetHappenComes",
                id: "UnitNO",
                text: "UnitNOName"
            });
            //批次查询 btn_search1
            $("#btn_search2").on("click", function () {
                var $gridList2 = $("#gridList2");

                var conn2 = $.buildPostParam("FAccountDate,FHappenComNO", "2");

                $gridList2.jqGrid('setGridParam', {
                    postData: conn2,
                }).trigger('reloadGrid');
            });
            //打印      
            $("#butnPrint2").on("click", function () {
                $("#print2").jqprint();
            });
            //导出
            $("#butnExport2").on("click", function () {
                var param = { id: "V_JSK_13_ML_StoLJKConAcco_Mid_DWCR2", param: Index.buildExportConn("FAccountDate,FHappenComNO".split(","), "2") };

                Index.defaultDate != $("#FAccountDate2").val() && (param.id = "V_JSK_16_MX_StoLJKListAcco_Arc_DWCR2");

                var url = "/Common/ExcelExportById?{0}".format($.param(param));

                location.href = url;
            });
            //来料单位
            $("#FHappenComNO3").bindSelect({
                url: "/WareHouse/Consignment/GetHappenComies",
                id: "UnitNO",
                text: "UnitNOName"
            });
            //批次查询 btn_search1
            $("#btn_search3").on("click", function () {
                var $gridList3 = $("#gridList3");

                var conn3 = $.buildPostParam("FAccountDate,FHappenComNO,FProductionNO", "3");

                $gridList3.jqGrid('setGridParam', {
                    postData: conn3,
                }).trigger('reloadGrid');
            });
            //打印      
            $("#butnPrint3").on("click", function () {
                $("#print3").jqprint();
            });
            //导出
            $("#butnExport3").on("click", function () {
                var param = { id: "V_JSK_14_MX_StoLJKListAcco_Mid_LJCR", param: Index.buildExportConn("FAccountDate,FHappenComNO,FProductionNO".split(","), "1") };
                
                Index.defaultDate != $("#FAccountDate3").val() && (param.id = "V_JSK_16_MX_StoLJKListAcco_Arc_LJCR");

                var url = "/Common/ExcelExportById?{0}".format($.param(param));

                location.href = url;
            });
            //领料单位
            $("#FHappenComNO4").bindSelect({
                url: "/WareHouse/Consignment/GetHappenComes",
                id: "UnitNO",
                text: "UnitNOName"
            });
            //批次查询 btn_search1
            $("#btn_search4").on("click", function () {
                var $gridList4 = $("#gridList4");

                var conn4 = $.buildPostParam("FAccountDate,FHappenComNO,FProductionNO", "4");

                $gridList4.jqGrid('setGridParam', {
                    postData: conn4,
                }).trigger('reloadGrid');
            });
            //打印      
            $("#butnPrint4").on("click", function () {
                $("#print4").jqprint();
            });
            //导出
            $("#butnExport4").on("click", function () {
                var param = { id: "V_JSK_14_MX_StoLJKListAcco_Mid_LJCR2", param: Index.buildExportConn("FAccountDate,FHappenComNO".split(","), "2") };

                Index.defaultDate != $("#FAccountDate2").val() && (param.id = "V_JSK_16_MX_StoLJKListAcco_Arc_LJCR2");

                var url = "/Common/ExcelExportById?{0}".format($.param(param));

                location.href = url;
            });
        },
        buildExportConn: function (params, num) {
            var conn = "";

            !num && (num = "");

            params.forEach(function (item) {
                var val = $("#{0}{1}".format(item, num)).val();

                !!val && (conn += ("and {0} = '{1}'".format(item, val)));
            });

            return conn;
        },
        loadDataList: function () {
            var conn1 = $.buildPostParam("FAccountDate,FHappenComNO", "1");

            var $gridList1 = $("#gridList1");

            $gridList1.dataGridForJson({
                url: "/WareHouse/Consignment/GetConsignmentInstocks",
                postData: conn1,
                height: $(window).height() - 240,
                colModel: [
                { label: '来料单位', name: 'FHappenComNO', width: 120, align: 'left', sortable: false},
                { label: '来料单位名称', name: 'FHappenComName', width: 180, align: 'left', sortable: false },
                { label: '入库数量', name: 'FQuantity', width: 100, align: 'right', sortable: false },
                { label: '入库金额<br/>（元）', name: 'FMoney', width: 100, align: 'right', sortable: false, formatter: 'number'  },
                 { label: '', name: '', width: $(window).width() - 570, align: 'left' }
                ],
                pager: "#gridPager1",
                sortname: 'FHappenComNO',
                sortorder: "asc",
                viewrecords: true,
                rownumWidth: 50,
                onSelectRow: function (rowId) {

                },
                loadComplete: function (data) {
                    Index.dataList["0"] = data.rows;

                    var columnInfo = [
                              { caption: '来料单位', name: 'FHappenComNO'},
                              { caption: '来料单位名称', name: 'FHappenComName'},
                              { caption: '入库数量', name: 'FQuantity'},
                              { caption: '入库金额<br/>（元）', name: 'FMoney'}
                    ];

                    var title = Index.titlies[0].format(new Date().format("yyyy年MM月"))

                    Index.renderPrintData($("#print1"), data.rows, columnInfo, title);
                }
            });

            $gridList1.jqGrid('setFrozenColumns');

            $gridList1.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
            
            var conn2 = $.buildPostParam("FAccountDate,FHappenComNO", "2");

            var $gridList2 = $("#gridList2");

            $gridList2.dataGridForJson({
                url: "/WareHouse/Consignment/GetConsignmentOutstocks",
                postData: conn2,
                height: $(window).height() - 240,
                colModel: [
                { label: '领料单位', name: 'FHappenComNO', width: 120, align: 'left', sortable: false },
                { label: '领料单位名称', name: 'FHappenComName', width: 180, align: 'left', sortable: false },
                { label: '出库数量', name: 'FQuantity', width: 100, align: 'right', sortable: false },
                { label: '出库金额<br/>（元）', name: 'FMoney', width: 100, align: 'right', sortable: false, formatter: 'number' },
                { label: '', name: '', width: $(window).width() - 550, align: 'left' }
                ],
                pager: "#gridPager2",
                sortname: 'FHappenComNO',
                sortorder: "asc",
                viewrecords: true,
                rownumWidth: 50,
                onSelectRow: function (rowId) {

                },
                loadComplete: function (data) {
                    Index.dataList["1"] = data.rows;

                    var columnInfo = [
                              { caption: '领料单位', name: 'FHappenComNO'},
                              { caption: '领料单位名称', name: 'FHappenComName'},
                              { caption: '出库数量', name: 'FQuantity'},
                              { caption: '出库金额<br/>（元）', name: 'FMoney'}
                    ];

                    var title = Index.titlies[1].format(new Date().format("yyyy年MM月"))

                    Index.renderPrintData($("#print2"), data.rows, columnInfo, title);
                }
            });

            $gridList2.jqGrid('setFrozenColumns');

            $gridList2.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');

            var conn3 = $.buildPostParam("FAccountDate,FHappenComNO,FProductionNO", "3");

            var $gridList3 = $("#gridList3");

            $gridList3.dataGridForJson({
                url: "/WareHouse/Consignment/GetConsignmentInstockStatistics",
                postData: conn3,
                height: $(window).height() - 240,
                colModel: [
                { label: '来料单位', name: 'FHappenComNO', width: 120, align: 'left', sortable: false},
                { label: '来料单位名称', name: 'FHappenComName', width: 160, align: 'left', sortable: false },
                { label: '零件编号', name: 'FProductionNO', width: 160, align: 'left', sortable: false },
                { label: '零件名称', name: 'FProductionName', width: 160, align: 'left', sortable: false},
                { label: '来料<br/>数量', name: 'Fquantity', width: 80, align: 'right', sortable: false},
                { label: '单价<br/>（元）', name: 'Fprice', width: 60, align: 'right', sortable: false },
                { label: '金额<br/>（元）', name: 'FAmount', width: 80, align: 'right', sortable: false, formatter: 'number' },
                { label: '制造单位', name: 'FProCompanyNO', width: 120, align: 'left', sortable: false},
                { label: '制造单位名称', name: 'FProCompanyName', width: 120, align: 'left', sortable: false},
                 { label: '', name: '', width: $(window).width() - 1150, align: 'left' }
                ],
                pager: "#gridPager3",
                sortname: 'FHappenComNO',
                sortorder: "asc",
                viewrecords: true,
                rownumWidth: 50,
                onSelectRow: function (rowId) {

                },
                loadComplete: function (data) {
                    Index.dataList["2"] = data.rows;

                    var columnInfo = [
                              { caption: '来料单位名称', name: 'FHappenComName'},
                              { caption: '零件编号', name: 'FProductionNO'},
                              { caption: '零件名称', name: 'FProductionName'},
                              { caption: '来料数量', name: 'Fquantity'},
                              { caption: '单价<br/>（元）', name: 'Fprice'},
                              { caption: '金额<br/>（元）', name: 'FAmount'},
                              { caption: '制造单位', name: 'FProCompanyNO'},
                              { caption: '制造单位名称', name: 'FProCompanyName'}
                    ];

                    var title = Index.titlies[2].format(new Date().format("yyyy年MM月"))

                    Index.renderPrintData($("#print3"), data.rows, columnInfo, title);
                }
            });

            $gridList3.jqGrid('setFrozenColumns');

            $gridList3.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');

            var conn4 = $.buildPostParam("FAccountDate,FHappenComNO,FProductionNO", "4");

            var $gridList4 = $("#gridList4");

            $gridList4.dataGridForJson({
                url: "/WareHouse/Consignment/GetConsignmentOutstockStatistics",
                postData: conn4,
                height: $(window).height() - 240,
                colModel: [
                { label: '销售单位', name: 'FHappenComNO', width: 120, align: 'left', sortable: false},
                { label: '销售单位名称', name: 'FHappenComName', width: 160, align: 'left', sortable: false },
                { label: '零件编号', name: 'FProductionNO', width: 160, align: 'left', sortable: false },
                { label: '零件名称', name: 'FProductionName', width: 160, align: 'left', sortable: false},
                { label: '销售<br/>数量', name: 'Fquantity', width: 80, align: 'right', sortable: false},
                { label: '单价<br/>（元）', name: 'Fprice', width: 60, align: 'right', sortable: false },
                { label: '金额<br/>（元）', name: 'FAmount', width: 80, align: 'right', sortable: false, formatter: 'number'},
                { label: '制造单位', name: 'FProCompanyNO', width: 120, align: 'left', sortable: false},
                { label: '制造单位名称', name: 'FProCompanyName', width: 120, align: 'left', sortable: false},
                 { label: '', name: '', width: $(window).width() - 1150, align: 'left' }
                ],
                pager: "#gridPager4",
                sortname: 'FHappenComNO',
                sortorder: "asc",
                viewrecords: true,
                rownumWidth: 50,
                onSelectRow: function (rowId) {

                },
                loadComplete: function (data) {
                    Index.dataList["3"] = data.rows;

                    var columnInfo = [
                              { caption: '销售单位名称', name: 'FHappenComName'},
                              { caption: '零件编号', name: 'FProductionNO'},
                              { caption: '零件名称', name: 'FProductionName'},
                              { caption: '销售数量', name: 'Fquantity'},
                              { caption: '单价<br/>（元）', name: 'Fprice'},
                              { caption: '金额<br/>（元）', name: 'FAmount'},
                              { caption: '制造单位', name: 'FProCompanyNO'},
                              { caption: '制造单位名称', name: 'FProCompanyName'}
                    ];

                    var title = Index.titlies[3].format(new Date().format("yyyy年MM月"))

                    Index.renderPrintData($("#print4"), data.rows, columnInfo, title);
                }
            });

            $gridList4.jqGrid('setFrozenColumns');

            $gridList4.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        },
        renderPrintData: function (c, data, colunmInfo, title) {
            c.empty();

            var rows = 16;

            var max = data.length;

            var item = { page: 1, maxPage: 1, title: title, unit: Index.curUnit, user: Index.curUserName, date: Index.curDate, time: Index.curTime, table: null };

            var maxPage = Math.ceil(max / rows);

            item.maxPage = maxPage;

            for (var i = 0; i < maxPage; i++) {
                var isFirst = true;

                var start = i * rows, end = (i + 1) * rows;

                end > max && (end = max);

                var table = $("<table>"), pageItem = $("<div>").addClass("page");

                item.page = i + 1;

                for (var j = start; j < end; j++) {
                    var cur = data[j];

                    isFirst && (function () {
                        var title = $("<tr>");

                        for (var idx in colunmInfo) {
                            $("<th>").html(colunmInfo[idx].caption).appendTo(title);
                        }

                        title.appendTo(table);

                        isFirst = false;
                    })();

                    !isFirst && (function () {
                        var row = $("<tr>");

                        for (var idx in colunmInfo) {
                            $("<td>").text(cur[colunmInfo[idx].name]).appendTo(row);
                        }

                        row.appendTo(table);
                    })();
                }

                item.table = "<table>{0}</table>".format(table.html());

                pageItem.html(Index.printItemTemplate.format(item)).appendTo(c);
            }
        }
    };
</script>



<div class="layout" id="layout" style="width: 100%;">
    <ul id="myTab" class="nav nav-tabs" style="margin: 5px 0 0 0">
        <li class="active"><a href="#tab1" data-toggle="tab">来料单位汇总</a></li>
        <li><a href="#tab2" data-toggle="tab">领料单位汇总</a></li>
        <li><a href="#tab3" data-toggle="tab">入库统计</a></li>
        <li><a href="#tab4" data-toggle="tab">销售统计</a></li>
    </ul>
    <div id="myTabContent" class="tab-content">
        <div class="tab-pane fade in active" id="tab1">
            <div class="tool_c">
                <div class="btn-group  input-width-185">
                    &nbsp;台账日期<br />
                    <input id="FAccountDate1" name="date" type="text" class="txt_common form-control" date-control />
                </div>
                <div class="btn-group input-width-185">
                    &nbsp;	来料单位<br />
                    <select id="FHappenComNO1" name="" class="form-control FHappenCompanyNO">
                        <option value="">==请选择==</option>
                    </select>
                </div>
                <div class="btn-group">
                    <a id="btn_search1" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span>查询</a>
                    <a class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span>&nbsp刷新</a>
                    <a id="butnPrint1" class="btn btn-primary center-block"><span class="glyphicon glyphicon-print"></span>&nbsp打印</a>
                    <a id="butnExport1" class="btn btn-primary center-block"><span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
                </div>
            </div>
            <div class="grid_list_1_c" style="margin-top: 5px;">
                <table id="gridList1"></table>
                <div id="gridPager1"></div>
            </div>
            <div id="print1" class="print">
                <div class="page break_page">
                    <h1>{title}</h1>
                    <div class="top">
                        单位：<div class="unit">{unit}</div>
                        <div class="right_page">第{page}页，共{maxPage}页</div>
                    </div>
                    <div class="table_c">
                        {table}
                    </div>
                    <footer>
                        <span>打印人员：<label>{user}</label></span> <span>打印日期：<label>{date}</label><label>{time}</label></span>
                    </footer>
                </div>
            </div>
        </div>
        <div class="tab-pane fade" id="tab2">
            <div class="tool_c">
               <div class="btn-group  input-width-185">
                    &nbsp;台账日期<br />
                    <input id="FAccountDate2" name="date" type="text" class="txt_common form-control" date-control />
                </div>
                <div class="btn-group input-width-185">
                    &nbsp;	领料单位<br />
                    <select id="FHappenComNO2" name="" class="form-control">
                        <option value="">==请选择==</option>
                    </select>
                </div>
                <div class="btn-group">
                    <a id="btn_search2" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span>查询</a>
                    <a class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span>&nbsp刷新</a>
                    <a id="butnPrint2" class="btn btn-primary center-block"><span class="glyphicon glyphicon-print"></span>&nbsp打印</a>
                    <a id="butnExport2" class="btn btn-primary center-block"><span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
                </div>
            </div>
            <div class="grid_list_1_c" style="margin-top: 5px;">
                <table id="gridList2"></table>
                <div id="gridPager2"></div>
            </div>
            <div id="print2" class="print">
                <div class="page break_page">
                    <h1>{title}</h1>
                    <div class="top">
                        单位：<div class="unit">{unit}</div>
                        <div class="right_page">第{page}页，共{maxPage}页</div>
                    </div>
                    <div class="table_c">
                        {table}
                    </div>
                    <footer>
                        <span>打印人员：<label>{user}</label></span> <span>打印日期：<label>{date}</label><label>{time}</label></span>
                    </footer>
                </div>
            </div>
        </div>
        <div class="tab-pane fade" id="tab3">
            <div class="tool_c">
                <div class="btn-group  input-width-185">
                    &nbsp;台账日期<br />
                    <input id="FAccountDate3" name="date" type="text" class="txt_common form-control" date-control />
                </div>
                <div class="btn-group input-width-185">
                    &nbsp;	来料单位<br />
                    <select id="FHappenComNO3" name="" class="form-control FHappenCompanyNO">
                        <option value="">==请选择==</option>
                    </select>
                </div>
                <div class="btn-group  input-width-185">
                    &nbsp;产品编号<br />
                    <input id="FProductionNO3" name="date" type="text" class="txt_common form-control"/>
                </div>
                <div class="btn-group">
                    <a id="btn_search3" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span>查询</a>
                    <a class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span>&nbsp刷新</a>
                    <a id="butnPrint3" class="btn btn-primary center-block"><span class="glyphicon glyphicon-print"></span>&nbsp打印</a>
                    <a id="butnExport3" class="btn btn-primary center-block"><span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
                </div>
            </div>
            <div class="grid_list_1_c" style="margin-top: 5px;">
                <table id="gridList3"></table>
                <div id="gridPager3"></div>
            </div>
            <div id="print3" class="print">
                <div class="page break_page">
                    <h1>{title}</h1>
                    <div class="top">
                        单位：<div class="unit">{unit}</div>
                        <div class="right_page">第{page}页，共{maxPage}页</div>
                    </div>
                    <div class="table_c">
                        {table}
                    </div>
                    <footer>
                        <span>打印人员：<label>{user}</label></span> <span>打印日期：<label>{date}</label><label>{time}</label></span>
                    </footer>
                </div>
            </div>
        </div>
        <div class="tab-pane fade" id="tab4">
            <div class="tool_c">
                <div class="btn-group  input-width-185">
                    &nbsp;台账日期<br />
                    <input id="FAccountDate4" name="date" type="text" class="txt_common form-control" date-control />
                </div>
                <div class="btn-group input-width-185">
                    &nbsp;	领料单位<br />
                    <select id="FHappenComNO4" name="" class="form-control">
                        <option value="">==请选择==</option>
                    </select>
                </div>
                <div class="btn-group  input-width-185">
                    &nbsp;产品编号<br />
                    <input id="FProductionNO4" name="date" type="text" class="txt_common form-control"/>
                </div>
                <div class="btn-group">
                    <a id="btn_search4" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span>查询</a>
                    <a class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span>&nbsp刷新</a>
                    <a id="butnPrint4" class="btn btn-primary center-block"><span class="glyphicon glyphicon-print"></span>&nbsp打印</a>
                    <a id="butnExport4" class="btn btn-primary center-block"><span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
                </div>
            </div>
            <div class="grid_list_1_c" style="margin-top: 5px;">
                <table id="gridList4"></table>
                <div id="gridPager4"></div>
            </div>
            <div id="print4" class="print">
                <div class="page break_page">
                    <h1>{title}</h1>
                    <div class="top">
                        单位：<div class="unit">{unit}</div>
                        <div class="right_page">第{page}页，共{maxPage}页</div>
                    </div>
                    <div class="table_c">
                        {table}
                    </div>
                    <footer>
                        <span>打印人员：<label>{user}</label></span> <span>打印日期：<label>{date}</label><label>{time}</label></span>
                    </footer>
                </div>
            </div>
        </div>
    </div>
</div>


